<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%" max-height="600">
      <el-table-column
        prop="name"
        label="用户名"
        width="100"
        show-overflow-tooltip
      >
        <template slot-scope="{ row }">
          <span>{{ row.sysUser ? row.sysUser.userName : '--' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="文件名称"> </el-table-column>
      <el-table-column prop="content" label="内容"> </el-table-column>
      <el-table-column prop="createTime" label="是否批阅" width="80">
        <template slot-scope="{ row }">
          <span v-show="row.eduTeacherComments.id">是</span>
          <span v-show="!row.eduTeacherComments.id">否</span>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="160">
      </el-table-column>
      <el-table-column label="操作" width="150" fixed="right">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button
              type="primary"
              size="mini"
              @click="handleCheck(row)"
              :disabled="row.eduTeacherComments.id"
            >
              {{ row.eduTeacherComments.id ? '已批阅' : '批阅' }}
            </el-button>
            <el-button type="danger" size="mini" @click="handleDelete(row)"
              >删除</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>
<script>
import {
  eduStudentJobsQuery,
  eduStudentJobsDelete,
} from '@/api/admin/teach/eduStudentJobs.js'
export default {
  data() {
    return {
      dialogVisible: false,
      listQuery: {
        page: 1,
        limit: 10,
        jobId: undefined,
        createBy: this.$store.getters.userId,
      },
      tableData: [],
      pageObj: {},
    }
  },
  props: ['row'],
  watch: {
    row: {
      immediate: true,
      handler(obj) {
        if (obj && obj.id) {
          this.listQuery.jobId = obj.id
          this.getList()
        }
      },
    },
  },
  mounted() {},
  methods: {
    async getList() {
      let res = await eduStudentJobsQuery(this.listQuery)
      this.tableData = res.data.data
      this.pageObj = res.data
      this.dialogVisible = true
    },
    handleCheck(row) {
      this.$bus.$emit('showDialogCheckAnswer', row)
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      eduStudentJobsDelete(row.id).then((res) => {
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>